#include <CMS8S6990.H>
#include "main.h"

/**
  * @brief  PV数组设置函数
  * @param  PV数组指针
  * @param  要设置的值
  * @retval 无
  */
void PvNixieBuf_Set(int8_t* GcPvNixieBuf, uint16_t Value)
{
	GcPvNixieBuf[3] = (Value / 1000) %10;
	GcPvNixieBuf[2] = (Value / 100) %10;
	GcPvNixieBuf[1] = (Value / 10) %10;
	GcPvNixieBuf[0] = Value %10;
}

/**
  * @brief  SV数组设置函数
  * @param  SV数组指针
  * @param  要设置的值
  * @retval 无
  */
void SvNixieBuf_Set(uint8_t* GcSvNixieBuf, int16_t Value)
{
	if(Value >= 0)
	{
		GcSvNixieBuf[3] = (Value / 1000) %10;
		GcSvNixieBuf[2] = (Value / 100) %10;
		GcSvNixieBuf[1] = (Value / 10) %10;
		GcSvNixieBuf[0] = Value %10;
	}
	else if(Value < 0)
	{
		Value = -Value;
		GcSvNixieBuf[3] = (Value / 1000) %10;
		GcSvNixieBuf[2] = (Value / 100) %10;
		GcSvNixieBuf[1] = (Value / 10) %10;
		GcSvNixieBuf[0] = Value %10;
	}
}

/**
  * @brief  SV PV显示函数
  * @param 	无
  * @param  无
  * @retval 无
  */
void Nixie_Show(Nixie_Position_t Nixie_Position)
{
	uint8_t temp = 0;
	if(Nixie_Position == SV)
	{
//		GusSvValue = SV_MENU;
		if(GusSvValue >= 0)
		{
			if(GusSvValue < 10)
			{
				Nixie_SetBuf(5, 10);
				Nixie_SetBuf(6, 10);
				Nixie_SetBuf(7, 10);
				Nixie_SetBuf(8, GcSvNixieBuf[0]);
			}
			else if(GusSvValue >= 10 && GusSvValue < 100)
			{
				Nixie_SetBuf(5, 10);
				Nixie_SetBuf(6, 10);
				Nixie_SetBuf(7, GcSvNixieBuf[1]);
				Nixie_SetBuf(8, GcSvNixieBuf[0]);
			}
			else if(GusSvValue >= 100 && GusSvValue < 1000)
			{
				Nixie_SetBuf(5, 10);
				Nixie_SetBuf(6, GcSvNixieBuf[2]);
				Nixie_SetBuf(7, GcSvNixieBuf[1]);
				Nixie_SetBuf(8, GcSvNixieBuf[0]);
			}
			else if(GusSvValue >= 1000)
			{
				Nixie_SetBuf(8, GcSvNixieBuf[0]);
				Nixie_SetBuf(7, GcSvNixieBuf[1]);
				Nixie_SetBuf(6, GcSvNixieBuf[2]);
				Nixie_SetBuf(5, GcSvNixieBuf[3]);
			}
		}
		else if(GusSvValue < 0)
		{
			temp = GusSvValue;
			temp = -temp;
			if(temp < 10)
			{
				Nixie_SetBuf(5, 10);
				Nixie_SetBuf(6, 10);
				Nixie_SetBuf(7, 27);
				Nixie_SetBuf(8, GcSvNixieBuf[0]);
			}
			else if(temp >= 10 && temp < 100)
			{
				Nixie_SetBuf(5, 10);
				Nixie_SetBuf(6, 27);
				Nixie_SetBuf(7, GcSvNixieBuf[1]);
				Nixie_SetBuf(8, GcSvNixieBuf[0]);
			}
			else if(temp >= 100 && temp < 1000)
			{
				Nixie_SetBuf(5, 27);
				Nixie_SetBuf(6, GcSvNixieBuf[2]);
				Nixie_SetBuf(7, GcSvNixieBuf[1]);
				Nixie_SetBuf(8, GcSvNixieBuf[0]);
				
			}
			else if(temp >= 1000)
			{
				Nixie_SetBuf(8, GcSvNixieBuf[0]);
				Nixie_SetBuf(7, GcSvNixieBuf[1]);
				Nixie_SetBuf(6, GcSvNixieBuf[2]);
				Nixie_SetBuf(5, GcSvNixieBuf[3]);
			}
		}
	}
	else if(Nixie_Position == PV)
	{
		if(GusPvValue < 10)
		{
			Nixie_SetBuf(1, 10);
			Nixie_SetBuf(2, 10);
			Nixie_SetBuf(3, 10);
			Nixie_SetBuf(4, GcPvNixieBuf[0]);
		}
		else if(GusPvValue >= 10 && GusPvValue < 100)
		{
			Nixie_SetBuf(1, 10);
			Nixie_SetBuf(2, 10);
			Nixie_SetBuf(3, GcPvNixieBuf[1]);
			Nixie_SetBuf(4, GcPvNixieBuf[0]);
		}
		else if(GusPvValue >= 100 && GusPvValue < 1000)
		{
			Nixie_SetBuf(1, 10);
			Nixie_SetBuf(2, GcPvNixieBuf[2]);
			Nixie_SetBuf(3, GcPvNixieBuf[1]);
			Nixie_SetBuf(4, GcPvNixieBuf[0]);
		}
		else if(GusPvValue >= 1000)
		{
			Nixie_SetBuf(4, GcPvNixieBuf[0]);
			Nixie_SetBuf(3, GcPvNixieBuf[1]);
			Nixie_SetBuf(2, GcPvNixieBuf[2]);
			Nixie_SetBuf(1, GcPvNixieBuf[3]);
		}
	}
}

/**
  * @brief  SV_Value设置函数 (SV，SC，SLL，AL1,AL2专用（含负数范围的选项）)
  * @param 	主菜单缓存数组索引，范围：INDEX_SV_MENU，INDEX_SC, INDEX_SLL
  * @retval 无
  */
void SV_Set_ForSV(uint8_t Index)
{
	if(GusSvValue >= 0)
	{
		if(GucKeyNum == KEY_TURN)
		{
			GucSvSetSelect ++;
			GucSvSetSelect %= 3;
		}
		if(GucKeyNum == KEY_UP)
		{
			GcSvNixieBuf[GucSvSetSelect] ++;
			if(GcSvNixieBuf[0] >= 10)
			{
				GcSvNixieBuf[0] = 0;
				GcSvNixieBuf[1] ++;
			}
			if(GcSvNixieBuf[1] >= 10)
			{
				GcSvNixieBuf[1] = 0;
				GcSvNixieBuf[2] ++;
			}
			if(GcSvNixieBuf[2] >= 10)
			{
				GcSvNixieBuf[0] = 9;
				GcSvNixieBuf[1] = 9;
				GcSvNixieBuf[2] = 9;
				GcSvNixieBuf[3] = 0;
			}
			GusSvValue = GcSvNixieBuf[3] * 1000 + GcSvNixieBuf[2] * 100 + GcSvNixieBuf[1] * 10 + GcSvNixieBuf[0];
			if(GusSvValue > 999){GusSvValue = 999;}
			//将更新的SV_Valueֵ保存
//			SetMainMenuBuf(Index);							/* 将显示值写入对应主菜单缓存数组 */
			/*还需写入FLASH*/
		}
		/*****************长按逻辑********************/
		if(key_list[0].key_longflag == 1)
		{
			GucCountMenu = 0;
			GcSvNixieBuf[GucSvSetSelect] ++;
			if(GcSvNixieBuf[0] >= 10)
			{
				GcSvNixieBuf[0] = 0;
				GcSvNixieBuf[1] ++;
			}
			if(GcSvNixieBuf[1] >= 10)
			{
				GcSvNixieBuf[1] = 0;
				GcSvNixieBuf[2] ++;
			}
			if(GcSvNixieBuf[2] >= 10)
			{
				GcSvNixieBuf[0] = 9;
				GcSvNixieBuf[1] = 9;
				GcSvNixieBuf[2] = 9;
				GcSvNixieBuf[3] = 0;
			}
			GusSvValue = GcSvNixieBuf[3] * 1000 + GcSvNixieBuf[2] * 100 + GcSvNixieBuf[1] * 10 + GcSvNixieBuf[0];
			if(GusSvValue > 999){GusSvValue = 999;}
			//将更新的SV_Valueֵ保存
//			SetMainMenuBuf(Index);							/* 将显示值写入对应主菜单缓存数组 */
			/*还需写入FLASH*/
			delay_ms(20);
		}
		else if(key_list[1].key_longflag == 1)
		{
			GucCountMenu = 0;
			GcSvNixieBuf[GucSvSetSelect] --;
			if(GcSvNixieBuf[0] < 0)
			{
				GcSvNixieBuf[0] = 9;
				GcSvNixieBuf[1] --;
			}
			if(GcSvNixieBuf[1] < 0)
			{
				GcSvNixieBuf[1] = 9;
				GcSvNixieBuf[2] --;
			}
			if(GcSvNixieBuf[2] < 0)
			{
				GcSvNixieBuf[0] = 0;
				GcSvNixieBuf[1] = 0;
				GcSvNixieBuf[2] = 0;
				GcSvNixieBuf[3] = 0;
				GucSvValueSign = 1;
			}
			//将更新的SV_Valueֵ保存
			GusSvValue = GcSvNixieBuf[3] * 1000 + GcSvNixieBuf[2] * 100 + GcSvNixieBuf[1] * 10 + GcSvNixieBuf[0];
			if(GucSvValueSign == 1)
			{
				GucSvValueSign = 0;
				GusSvValue = -1;
				SvNixieBuf_Set(GcSvNixieBuf, GusSvValue);							/* 写入显示缓存数组，不分正负均可写入 */
			}
//			SetMainMenuBuf(Index);													/* 将显示值写入对应主菜单缓存数组 */
			/*还需写入FLASH*/
			delay_ms(20);
		}
		/****************************************/
		if(GucKeyNum == KEY_DOWN)
		{
			GcSvNixieBuf[GucSvSetSelect] --;
			if(GcSvNixieBuf[0] < 0)
			{
				GcSvNixieBuf[0] = 9;
				GcSvNixieBuf[1] --;
			}
			if(GcSvNixieBuf[1] < 0)
			{
				GcSvNixieBuf[1] = 9;
				GcSvNixieBuf[2] --;
			}
			if(GcSvNixieBuf[2] < 0)
			{
				GcSvNixieBuf[0] = 0;
				GcSvNixieBuf[1] = 0;
				GcSvNixieBuf[2] = 0;
				GcSvNixieBuf[3] = 0;
				GucSvValueSign = 1;
			}
			//将更新的SV_Valueֵ保存
			GusSvValue = GcSvNixieBuf[3] * 1000 + GcSvNixieBuf[2] * 100 + GcSvNixieBuf[1] * 10 + GcSvNixieBuf[0];
			if(GucSvValueSign == 1)
			{
				GucSvValueSign = 0;
				GusSvValue = -1;
				SvNixieBuf_Set(GcSvNixieBuf, GusSvValue);							/* 写入显示缓存数组，不分正负均可写入 */
			}
//			SetMainMenuBuf(Index);							/* 将显示值写入对应主菜单缓存数组 */
			/*还需写入FLASH*/
		}
		if(LCK == 0)
		{
			SetMainMenuBuf(Index);							/* 将显示值写入对应主菜单缓存数组 */
		}
		else if(LCK == 1)
		{
			if(Index == INDEX_SV_MENU || Index == INDEX_AL1 || Index == INDEX_AL2 )
			{
				SetMainMenuBuf(Index);							/* 将显示值写入对应主菜单缓存数组 */
			}
			else
			{
				_nop_();
			}
		}
		else if(LCK == 11)
		{
			if(Index == INDEX_SV_MENU)
			{
				SetMainMenuBuf(Index);							/* 将显示值写入对应主菜单缓存数组 */
			}
			else
			{
				_nop_();
			}
		}
		else
		{
			_nop_();
		}
		if(GucSvSetSelect==0 && GucSvSetFlashFlag==1){Nixie_SetBuf(8, 10);}
		else{Nixie_SetBuf(8, GcSvNixieBuf[0]);}
		if(GucSvSetSelect==1 && GucSvSetFlashFlag==1){Nixie_SetBuf(7, 10);}
		else{Nixie_SetBuf(7, GcSvNixieBuf[1]);}
		if(GucSvSetSelect==2 && GucSvSetFlashFlag==1){Nixie_SetBuf(6, 10);}
		else{Nixie_SetBuf(6, GcSvNixieBuf[2]);}
		if(GucSvSetSelect==3 && GucSvSetFlashFlag==1){Nixie_SetBuf(5, 10);}
		else{Nixie_SetBuf(5, GcSvNixieBuf[3]);}
	}
	else if(GusSvValue < 0)															/* SV值小于零判断 */
	{
		if(GucKeyNum == KEY_TURN)
		{
			GucSvSetSelect ++;
			GucSvSetSelect %= 2;
		}
		if(GucKeyNum == KEY_DOWN)
		{
			GcSvNixieBuf[GucSvSetSelect] ++;
			if(GcSvNixieBuf[0] >= 10)
			{
				GcSvNixieBuf[0] = 0;
				GcSvNixieBuf[1] ++;
			}
			if(GcSvNixieBuf[1] >= 5)
			{
				GcSvNixieBuf[1] = 5;
				GcSvNixieBuf[0] = 0;
				GucSvValueSign = 2;
			}
			GusSvValue = GcSvNixieBuf[1] * (-10) - GcSvNixieBuf[0];
			if(GucSvValueSign == 2)
			{
				GucSvValueSign = 0;
				SvNixieBuf_Set(GcSvNixieBuf, GusSvValue);					/* 将显示值写入对应显示缓存数组   */
			}
			//将更新的SV_Valueֵ保存
//			SetMainMenuBuf(Index);							/* 将显示值写入对应主菜单缓存数组 */
			/*还需写入FLASH*/
		}
		if(GucKeyNum == KEY_UP)
		{
			GcSvNixieBuf[GucSvSetSelect] --;
			if(GcSvNixieBuf[0] < 0)
			{
				GcSvNixieBuf[0] = 9;
				GcSvNixieBuf[1] --;
			}
			if(GcSvNixieBuf[1] < 0)
			{
				GcSvNixieBuf[1] = 0;
				GcSvNixieBuf[0] = 0;
				GucSvValueSign = 3;
			}
			//将更新的SV_Valueֵ保存
			GusSvValue = GcSvNixieBuf[1] * (-10) - GcSvNixieBuf[0];
			if(GucSvValueSign == 3)
			{
				GucSvValueSign = 0;
				SvNixieBuf_Set(GcSvNixieBuf, GusSvValue);
			}
//			SetMainMenuBuf(Index);							/* 将显示值写入对应主菜单缓存数组 */
			/*还需写入FLASH*/
		}
		if(LCK == 0)
		{
			SetMainMenuBuf(Index);							/* 将显示值写入对应主菜单缓存数组 */
		}
		else if(LCK == 1)
		{
			if(Index == INDEX_SV_MENU || Index == INDEX_AL1 || Index == INDEX_AL2 )
			{
				SetMainMenuBuf(Index);							/* 将显示值写入对应主菜单缓存数组 */
			}
			else
			{
				_nop_();
			}
		}
		else if(LCK == 11)
		{
			if(Index == INDEX_SV_MENU)
			{
				SetMainMenuBuf(Index);							/* 将显示值写入对应主菜单缓存数组 */
			}
			else
			{
				_nop_();
			}
		}
		else
		{
			_nop_();
		}
		//数码管更新显示
		if(GucSvSetSelect==0 && GucSvSetFlashFlag==1){Nixie_SetBuf(8, 10);}
		else{Nixie_SetBuf(8, GcSvNixieBuf[0]);}
		if(GucSvSetSelect==1 && GucSvSetFlashFlag==1){Nixie_SetBuf(7, 10);}
		else{Nixie_SetBuf(7, GcSvNixieBuf[1]);}
		if(GucSvSetSelect==2 && GucSvSetFlashFlag==1){Nixie_SetBuf(6, 10);}
		else{Nixie_SetBuf(6, GcSvNixieBuf[2]);}
		Nixie_SetBuf(5, 27);
	}
}

/**
  * @brief  SV_Value设置函数 
  * @param 	无
  * @param  无
  * @retval 无
  */
void SV_Set(uint8_t ShowValue)
{
	if(GucKeyNum == KEY_TURN)
	{
		GucSvSetSelect ++;
		GucSvSetSelect %= 3;
	}
	if(GucKeyNum == KEY_UP)
	{
		GcSvNixieBuf[GucSvSetSelect] ++;
		if(GcSvNixieBuf[0] >= 10)
		{
			GcSvNixieBuf[0] = 0;
            GcSvNixieBuf[1] ++;
		}
		if(GcSvNixieBuf[1] >= 10)
		{
			GcSvNixieBuf[1] = 0;
            GcSvNixieBuf[2] ++;
		}
		if(GcSvNixieBuf[2] >= 10)
		{
			GcSvNixieBuf[0] = 0;
			GcSvNixieBuf[1] = 0;
			GcSvNixieBuf[2] = 0;
			GcSvNixieBuf[3] = 0;
		}
		//将更新的SV_Valueֵ保存
		GusSvValue = GcSvNixieBuf[3] * 1000 + GcSvNixieBuf[2] * 100 + GcSvNixieBuf[1] * 10 + GcSvNixieBuf[0];
		if(GusSvValue > 999){GusSvValue = 999;}
		
		if(LCK == 0)
		{
			SetMainMenuBuf(ShowValue);							/* 将显示值写入对应缓存数组 */
		}
		else if(LCK != 0)
		{
			if(ShowValue == INDEX_LCK || ShowValue == INDEX_COD)
			{
				SetMainMenuBuf(ShowValue);							/* 将显示值写入对应缓存数组 */
			}
			else
			{
				_nop_();
			}
		}
		/*还需写入FLASH*/
	}
	/*****************长按逻辑********************/
	if(ShowValue != INDEX_COD)
	{
		if(key_list[0].key_longflag == 1)
		{
			GucCountMenu = 0;
			GcSvNixieBuf[GucSvSetSelect] ++;
			if(GcSvNixieBuf[0] >= 10)
			{
				GcSvNixieBuf[0] = 0;
				GcSvNixieBuf[1] ++;
			}
			if(GcSvNixieBuf[1] >= 10)
			{
				GcSvNixieBuf[1] = 0;
				GcSvNixieBuf[2] ++;
			}
			if(GcSvNixieBuf[2] >= 10)
			{
				GcSvNixieBuf[0] = 9;
				GcSvNixieBuf[1] = 9;
				GcSvNixieBuf[2] = 9;
				GcSvNixieBuf[3] = 0;
			}
			GusSvValue = GcSvNixieBuf[3] * 1000 + GcSvNixieBuf[2] * 100 + GcSvNixieBuf[1] * 10 + GcSvNixieBuf[0];
			if(GusSvValue > 999){GusSvValue = 999;}
			//将更新的SV_Valueֵ保存
			if(LCK == 0)
			{
				SetMainMenuBuf(ShowValue);							/* 将显示值写入对应缓存数组 */
			}
			else if(LCK != 0)
			{
				if(ShowValue == INDEX_LCK || ShowValue == INDEX_COD)
				{
					SetMainMenuBuf(ShowValue);							/* 将显示值写入对应缓存数组 */
				}
				else
				{
					_nop_();
				}
			}
			/*还需写入FLASH*/
			delay_ms(20);
		}
		else if(key_list[1].key_longflag == 1)
		{
			GucCountMenu = 0;
			GcSvNixieBuf[GucSvSetSelect] --;
			if(GcSvNixieBuf[0] < 0)
			{
				GcSvNixieBuf[0] = 9;
				GcSvNixieBuf[1] --;
			}
			if(GcSvNixieBuf[1] < 0)
			{
				GcSvNixieBuf[1] = 9;
				GcSvNixieBuf[2] --;
			}
			if(GcSvNixieBuf[2] < 0)
			{
				GcSvNixieBuf[0] = 0;
				GcSvNixieBuf[1] = 0;
				GcSvNixieBuf[2] = 0;
				GcSvNixieBuf[3] = 0;
			}
			//将更新的SV_Valueֵ保存
			GusSvValue = GcSvNixieBuf[3] * 1000 + GcSvNixieBuf[2] * 100 + GcSvNixieBuf[1] * 10 + GcSvNixieBuf[0];
			if(GusSvValue < 0){GusSvValue = 0;}
			if(LCK == 0)
			{
				SetMainMenuBuf(ShowValue);							/* 将显示值写入对应缓存数组 */
			}
			else if(LCK != 0)
			{
				if(ShowValue == INDEX_LCK || ShowValue == INDEX_COD)
				{
					SetMainMenuBuf(ShowValue);							/* 将显示值写入对应缓存数组 */
				}
				else
				{
					_nop_();
				}
			}
			/*还需写入FLASH*/
			delay_ms(20);
		}
	}
	
	/****************************************/
	if(GucKeyNum == KEY_DOWN)
	{
		GcSvNixieBuf[GucSvSetSelect] --;
		if(GcSvNixieBuf[0] < 0)
		{
			GcSvNixieBuf[0] = 9;
            GcSvNixieBuf[1] --;
		}
		if(GcSvNixieBuf[1] < 0)
		{
			GcSvNixieBuf[1] = 9;
            GcSvNixieBuf[2] --;
		}
		if(GcSvNixieBuf[2] < 0)
		{
			GcSvNixieBuf[0] = 9;
			GcSvNixieBuf[1] = 9;
			GcSvNixieBuf[2] = 9;
			GcSvNixieBuf[3] = 0;
		}
		//将更新的SV_Valueֵ保存
		GusSvValue = GcSvNixieBuf[3] * 1000 + GcSvNixieBuf[2] * 100 + GcSvNixieBuf[1] * 10 + GcSvNixieBuf[0];
		if(GusSvValue < 0){GusSvValue = 0;}
		if(LCK == 0)
		{
			SetMainMenuBuf(ShowValue);							/* 将显示值写入对应缓存数组 */
		}
		else if(LCK != 0)
		{
			if(ShowValue == INDEX_LCK || ShowValue == INDEX_COD)
			{
				SetMainMenuBuf(ShowValue);							/* 将显示值写入对应缓存数组 */
			}
			else
			{
				_nop_();
			}
		}
		/*还需写入FLASH*/
	}
	//数码管更新显示
	if(GucSvSetSelect==0 && GucSvSetFlashFlag==1){Nixie_SetBuf(8, 10);}
	else{Nixie_SetBuf(8, GcSvNixieBuf[0]);}
	if(GucSvSetSelect==1 && GucSvSetFlashFlag==1){Nixie_SetBuf(7, 10);}
	else{Nixie_SetBuf(7, GcSvNixieBuf[1]);}
	if(GucSvSetSelect==2 && GucSvSetFlashFlag==1){Nixie_SetBuf(6, 10);}
	else{Nixie_SetBuf(6, GcSvNixieBuf[2]);}
	if(GucSvSetSelect==3 && GucSvSetFlashFlag==1){Nixie_SetBuf(5, 10);}
	else{Nixie_SetBuf(5, GcSvNixieBuf[3]);}
}

/**
  * @brief  主菜单显示处理函数
  * @param 	主菜单显示索引
  * @retval 无                                                                      
  */                                                                                
void Main_Menu_Handle(uint8_t GucMainMenuIndex)
{
//	if(GucKeyNum == KEY_SET)
//	{
//		GucMainMenuIndex %= 12;
//		GucSvSetSelect=0;
//		SetSvNixieBuf(GucMainMenuIndex);					/* 在主菜单模式下按SET切换选项，将主菜单缓存数组写入显示数组 */
//		GucMainMenuIndex++;
//	}
	switch(GucMainMenuIndex)
	{                                                                               
		case INDEX_SV_MENU:                                                         
		{                                                                           
			Nixie_SetBuf(1, 10);
			Nixie_SetBuf(2, 10);
			Nixie_SetBuf(3, 5);
			Nixie_SetBuf(4, 17);
			SV_Set_ForSV(INDEX_SV_MENU);													/*输出到数码管*/
			break;
		}
		case INDEX_AL1:
		{
			Nixie_SetBuf(1, 10);
			Nixie_SetBuf(2, 18);
			Nixie_SetBuf(3, 19);
			Nixie_SetBuf(4, 1);
			SV_Set_ForSV(INDEX_AL1);												/*输出到数码管*/
			break;
		}
		case INDEX_AL2:
		{
			Nixie_SetBuf(1, 10);
			Nixie_SetBuf(2, 18);
			Nixie_SetBuf(3, 19);
			Nixie_SetBuf(4, 2);
			SV_Set_ForSV(INDEX_AL2);												/*输出到数码管*/
			break;
		}
		case INDEX_AT:
		{
			Nixie_SetBuf(1, 10);
			Nixie_SetBuf(2, 18);
			Nixie_SetBuf(3, 20);
			Nixie_SetBuf(4, 21);
			SV_Set(INDEX_AT);												/*输出到数码管*/
			break;
		}
		case INDEX_P:
		{
			Nixie_SetBuf(1, 10);
			Nixie_SetBuf(2, 10);
			Nixie_SetBuf(3, 10);
			Nixie_SetBuf(4, 13);
			SV_Set(INDEX_P);												/*输出到数码管*/
			break;
		}
		case INDEX_OH:
		{
			Nixie_SetBuf(1, 10);
			Nixie_SetBuf(2, 10);
			Nixie_SetBuf(3, 28);
			Nixie_SetBuf(4, 29);
			SV_Set(INDEX_OH);												/*输出到数码管*/
			break;
		}
		
		case INDEX_I:
		{
			Nixie_SetBuf(1, 10);
			Nixie_SetBuf(2, 10);
			Nixie_SetBuf(3, 10);
			Nixie_SetBuf(4, 1);
			SV_Set(INDEX_I);												/*输出到数码管*/
			break;
		}
		case INDEX_D:
		{
			Nixie_SetBuf(1, 10);
			Nixie_SetBuf(2, 10);
			Nixie_SetBuf(3, 10);
			Nixie_SetBuf(4, 22);
			SV_Set(INDEX_D);												/*输出到数码管*/
			break;
		}
		case INDEX_Ar:
		{
			Nixie_SetBuf(1, 10);
			Nixie_SetBuf(2, 10);
			Nixie_SetBuf(3, 18);
			Nixie_SetBuf(4, 23);
			SV_Set(INDEX_Ar);												/*输出到数码管*/
			break;
		}
		case INDEX_T:
		{
			Nixie_SetBuf(1, 10);
			Nixie_SetBuf(2, 10);
			Nixie_SetBuf(3, 10);
			Nixie_SetBuf(4, 24);
			SV_Set(INDEX_T);												/*输出到数码管*/
			break;
		}
		case INDEX_SC:
		{
			Nixie_SetBuf(1, 10);
			Nixie_SetBuf(2, 10);
			Nixie_SetBuf(3, 5);
			Nixie_SetBuf(4, 15);
			SV_Set_ForSV(INDEX_SC);												/*输出到数码管*/
			break;
		}
		case INDEX_LCK:
		{
			Nixie_SetBuf(1, 10);
			Nixie_SetBuf(2, 19);
			Nixie_SetBuf(3, 25);
			Nixie_SetBuf(4, 16);
			SV_Set(INDEX_LCK);												/*输出到数码管*/
			break;
		}
		default:{
			break;
		}
	}
}

/**
  * @brief  工程师菜单显示处理函数
  * @param 	工程师菜单显示索引
  * @retval 无                                                                      
  */                                                                                
void Eng_Menu_Handle(uint8_t GucMainMenuIndex)  
{
	switch(GucMainMenuIndex)
	{
		case INDEX_COD:
		{
			Nixie_SetBuf(1, 10);
			Nixie_SetBuf(2, 15);
			Nixie_SetBuf(3, 28);
			Nixie_SetBuf(4, 22);
			SV_Set(INDEX_COD);
			break;
		}
		case INDEX_SLL:
		{
			Nixie_SetBuf(1, 10);
			Nixie_SetBuf(2, 5);
			Nixie_SetBuf(3, 19);
			Nixie_SetBuf(4, 19);
			SV_Set_ForSV(INDEX_SLL);
			break;
		}
		case INDEX_SLH:
		{
			Nixie_SetBuf(1, 10);
			Nixie_SetBuf(2, 5);
			Nixie_SetBuf(3, 19);
			Nixie_SetBuf(4, 29);
			SV_Set(INDEX_SLH);
			break;
		}
		case INDEX_AH1:
		{
			Nixie_SetBuf(1, 10);
			Nixie_SetBuf(2, 18);
			Nixie_SetBuf(3, 29);
			Nixie_SetBuf(4, 1);
			SV_Set(INDEX_AH1);
			break;
		}
		case INDEX_AH2:
		{
			Nixie_SetBuf(1, 10);                                                    
			Nixie_SetBuf(2, 18);
			Nixie_SetBuf(3, 29);
			Nixie_SetBuf(4, 2);
			SV_Set(INDEX_AH2);
			break;
		}
		case INDEX_DF :
		{
			Nixie_SetBuf(1, 10);
			Nixie_SetBuf(2, 10);
			Nixie_SetBuf(3, 22);
			Nixie_SetBuf(4, 30);
			SV_Set(INDEX_DF);
			break;
		}
		default:{
			break;
		}
	}
}    

/**
  * @brief  主菜单缓存数组设置函数，将SV_Value的值设置到Main_Menu_Table
  * @param 	主菜单选项值索引
  * @retval 无                                                                      
  */
void SetMainMenuBuf(uint8_t ShowValue)
{
	switch(ShowValue)
	{
		/* 主菜单选项 */
		case INDEX_SV_MENU	:{SV_MENU = GusSvValue;break;}
		case INDEX_AL1		:{AL1 	  = GusSvValue;break;}
		case INDEX_AL2		:{AL2 	  = GusSvValue;break;}
		case INDEX_AT		:{AT	  = GusSvValue;break;}
		case INDEX_P		:{P	      = GusSvValue;break;}
		case INDEX_OH		:{OH	  = GusSvValue;break;}
		case INDEX_I		:{I	      = GusSvValue;break;}
		case INDEX_D		:{D	      = GusSvValue;break;}
		case INDEX_Ar		:{Ar	  = GusSvValue;break;}
		case INDEX_T		:{T	      = GusSvValue;break;}
		case INDEX_SC		:{SC	  = GusSvValue;break;}
		case INDEX_LCK		:{LCK     = GusSvValue;break;}
		/* COD */
		case INDEX_COD		:{COD     = GusSvValue;break;}
		/* 工程师菜单选项 */
		case INDEX_SLL		:{SLL	  = GusSvValue;break;}
		case INDEX_SLH		:{SLH	  = GusSvValue;break;}
		case INDEX_AH1		:{AH1	  = GusSvValue;break;}
		case INDEX_AH2		:{AH2	  = GusSvValue;break;}
		case INDEX_DF		:{DF	  = GusSvValue;break;}
		
		default:{break;}
	}
}

/**
  * @brief  SV显示缓存数组设置函数，将Main_Menu_Table设置到SV_Value。
  * @param 	主菜单选项值索引
  * @retval 无                                                                      
  */     
void SetSvNixieBuf(uint8_t ShowValue)
{
	switch(ShowValue)
	{
		/* 主菜单选项 */
		case INDEX_SV_MENU	:{GusSvValue = SV_MENU; 	SvNixieBuf_Set(GcSvNixieBuf, GusSvValue);break;}
		case INDEX_AL1		:{GusSvValue = AL1;     	SvNixieBuf_Set(GcSvNixieBuf, GusSvValue);break;}
		case INDEX_AL2		:{GusSvValue = AL2;     	SvNixieBuf_Set(GcSvNixieBuf, GusSvValue);break;}
		case INDEX_AT		:{GusSvValue = AT;      	SvNixieBuf_Set(GcSvNixieBuf, GusSvValue);break;}
		case INDEX_P		:{GusSvValue = P;       	SvNixieBuf_Set(GcSvNixieBuf, GusSvValue);break;}
		case INDEX_OH		:{GusSvValue = OH;       	SvNixieBuf_Set(GcSvNixieBuf, GusSvValue);break;}
		case INDEX_I		:{GusSvValue = I;		  	SvNixieBuf_Set(GcSvNixieBuf, GusSvValue);break;}
		case INDEX_D		:{GusSvValue = D;		  	SvNixieBuf_Set(GcSvNixieBuf, GusSvValue);break;}
		case INDEX_Ar		:{GusSvValue = Ar;	  		SvNixieBuf_Set(GcSvNixieBuf, GusSvValue);break;}
		case INDEX_T		:{GusSvValue = T;		  	SvNixieBuf_Set(GcSvNixieBuf, GusSvValue);break;}
		case INDEX_SC		:{GusSvValue = SC;	  		SvNixieBuf_Set(GcSvNixieBuf, GusSvValue);break;}
		case INDEX_LCK		:{GusSvValue = LCK;	  		SvNixieBuf_Set(GcSvNixieBuf, GusSvValue);break;}
		/* COD */
		case INDEX_COD		:{GusSvValue = COD;	  		SvNixieBuf_Set(GcSvNixieBuf, GusSvValue);break;}
		/* 工程师菜单选项 */		
		case INDEX_SLL		:{GusSvValue = SLL;	  		SvNixieBuf_Set(GcSvNixieBuf, GusSvValue);break;}
		case INDEX_SLH		:{GusSvValue = SLH;	  		SvNixieBuf_Set(GcSvNixieBuf, GusSvValue);break;}
		case INDEX_AH1		:{GusSvValue = AH1;	  		SvNixieBuf_Set(GcSvNixieBuf, GusSvValue);break;}
		case INDEX_AH2		:{GusSvValue = AH2;	  		SvNixieBuf_Set(GcSvNixieBuf, GusSvValue);break;}
		case INDEX_DF		:{GusSvValue = DF ;	  		SvNixieBuf_Set(GcSvNixieBuf, GusSvValue);break;}
		
		default:{break;}
	}
//	while(i--);
}

/**
  * @brief  摄氏度转换为华氏度函数
  * @param 	摄氏度
  * @retval 华氏度                                                                     
  */
int16_t Centigrade_to_Fahrenheit(int16_t Centigrade)
{
	return (Centigrade) / 5 * 9 + 32;
}

/**
  * @brief  华氏度转换为摄氏度函数
  * @param 	华氏度
  * @retval 摄氏度                                                                     
  */
int16_t Fahrenheit_to_Centigrade(int16_t Fahrenheit)
{
	return (Fahrenheit - 32) * 5 / 9;
}

/**
* @brief  指示灯逻辑函数
* @param 	无
  * @retval 无                                                                     
  */
void LED_Logic(void)
{
	//ALM1:低于ALM1报警
	if(GsTemperature < AL1)
	{
		Nixie_SetBuf_forcase9(1, ALM1);
		
	}
	else
	{
		Nixie_SetBuf_forcase9(0, ~ALM1);
	}
	
	//ALM2:高于ALM2报警
	if(GsTemperature > AL2)
	{
		Nixie_SetBuf_forcase9(1, ALM2);
		
	}
	else
	{
		Nixie_SetBuf_forcase9(0, ~ALM2);
	}
}

/**
* @brief  参数限幅函数
* @param 	无
  * @retval 无                                                                     
  */
void parametric_limiting(void)
{
	if(AT != 0) {AT = 1;}else {AT = 0;}
	if(P <= 0) {P = 0;}else if(P >= 999){P = 999;}
	if(OH <= 0) {OH = 0;}else if(OH >= 100){OH = 100;}
	if(I <= 0) {I = 0;}else if(I >= 999){I = 999;}
	if(D <= 0) {D = 0;}else if(D >= 999){D = 999;}
	if(Ar <= 0) {Ar = 0;}else if(Ar >= 100){Ar = 100;}
	if(T <= 0) {T = 0;}else if(T >= 100){T = 999;}
	if(SC <= -50) {SC = -50;}else if(SC >= 199){SC = 199;}
	if(LCK <= 0) {LCK = 0;}else if(LCK >= 111){LCK = 111;}
}	

void temperature_limiting(void)
{
	if(GsTemperature >= SLH){GsTemperature = SLH;}
	else if(GsTemperature <= SLL){GsTemperature = SLH;}
}